SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[Inv_header](
	[id] [int] IDENTITY(1,1) NOT NULL,
	[status] [int] NOT NULL,
	[create_date] [datetime] NULL,
	[po_date] [datetime] NULL,
	[currency_code] [nvarchar](50) NULL,
	[invoice_date] [datetime] NULL,
	[invoice_number] [nvarchar](50) NULL,
	[po_number] [nvarchar](50) NULL,
	[remit_to] [nvarchar](50) NULL,
	[terms_discount_amount] [decimal](18, 0) NULL,
	[terms_discount_due_date] [datetime] NULL,
	[terms_discount_due_days] [int] NULL,
	[terms_discount_percent] [decimal](18, 0) NULL,
	[terms_net_due_date] [datetime] NULL,
	[terms_net_due_days] [int] NULL,
	[total_amount] [decimal](18, 0) NULL,
 CONSTRAINT [PK_Inv_header] PRIMARY KEY CLUSTERED 
(
	[id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
GO


SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[Inv_line](
	[id] [int] IDENTITY(1,1) NOT NULL,
	[status] [int] NOT NULL,
	[hid] [int] NOT NULL,
	[description] [nvarchar](50) NULL,
	[invoiced_qty] [decimal](18, 0) NULL,
	[line_number] [nvarchar](50) NULL,
	[unit] [nvarchar](50) NULL,
	[unit_price] [decimal](18, 0) NULL,
 CONSTRAINT [PK_Inv_line] PRIMARY KEY CLUSTERED 
(
	[id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
GO

ALTER TABLE [dbo].[Inv_line]  WITH CHECK ADD  CONSTRAINT [FK_Inv_line_Inv_header] FOREIGN KEY([hid])
REFERENCES [dbo].[Inv_header] ([id])
GO

ALTER TABLE [dbo].[Inv_line] CHECK CONSTRAINT [FK_Inv_line_Inv_header]
GO


SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[Inventory_header](
	[id] [int] IDENTITY(1,1) NOT NULL,
	[create_date] [datetime] NOT NULL,
	[status] [int] NOT NULL,
	[transaction_date] [datetime] NULL,
	[transaction_number] [varchar](50) NULL,
 CONSTRAINT [PK_Inventory_header1] PRIMARY KEY CLUSTERED 
(
	[id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
GO



SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[Inventory_line](
	[hid] [int] NOT NULL,
	[available_qty] [decimal](18, 0) NULL,
	[theoretical_qty] [decimal](18, 0) NULL,
	[expires_date] [datetime] NULL,
	[sku_number] [nvarchar](50) NULL,
	[unit_price] [decimal](18, 4) NULL,
	[unuse_qty] [decimal](18, 0) NULL,
	[UPC_number] [nvarchar](50) NULL,
	[id] [int] IDENTITY(1,1) NOT NULL,
	[vendor_product_number] [nvarchar](50) NULL,
	[status] [int] NOT NULL,
	[item_desc] [nvarchar](70) NULL,
 CONSTRAINT [PK_Inventory_line] PRIMARY KEY CLUSTERED 
(
	[id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
GO

ALTER TABLE [dbo].[Inventory_line]  WITH CHECK ADD  CONSTRAINT [FK_Inventory_line_Inventory_header] FOREIGN KEY([hid])
REFERENCES [dbo].[Inventory_header] ([id])
GO

ALTER TABLE [dbo].[Inventory_line] CHECK CONSTRAINT [FK_Inventory_line_Inventory_header]
GO




SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[po_header](
	[id] [int] IDENTITY(1,1) NOT NULL,
	[amount] [decimal](18, 0) NULL,
	[bill_to_addr] [nvarchar](50) NULL,
	[bill_to_city] [nvarchar](50) NULL,
	[bill_to_code] [nvarchar](50) NULL,
	[bill_to_contact_name] [nvarchar](50) NULL,
	[bill_to_contact_tel] [nvarchar](50) NULL,
	[bill_to_country] [nvarchar](50) NULL,
	[bill_to_name] [nvarchar](50) NULL,
	[bill_to_state] [nvarchar](50) NULL,
	[bill_to_zip] [nvarchar](50) NULL,
	[buyer_contact_tel] [nvarchar](50) NULL,
	[buyer_ident] [nvarchar](50) NULL,
	[buyer_ident_number] [nvarchar](50) NULL,
	[internal_code] [nvarchar](50) NULL,
	[create_date] [datetime] NULL,
	[currency_code] [nvarchar](50) NULL,
	[file_type] [nvarchar](50) NULL,
	[merchandise_type] [nvarchar](50) NULL,
	[nopackslip_desc] [nvarchar](50) NULL,
	[order_date] [datetime] NULL,
	[order_restrciton] [nvarchar](50) NULL,
	[pack_list_number] [nvarchar](50)  NULL,
	[partytoReceive_addr] [nvarchar](50) NULL,
	[partytoReceive_city] [nvarchar](50) NULL,
	[partytoReceive_code] [nvarchar](50) NULL,
	[partytoReceive_contact_name] [nvarchar](50) NULL,
	[partytoReceive_contact_tel] [nvarchar](50) NULL,
	[partytoReceive_country] [nvarchar](50) NULL,
	[partytoReceive_name] [nvarchar](50) NULL,
	[partytoReceive_state] [nvarchar](50) NULL,
	[partytoReceive_zip] [nvarchar](50) NULL,
	[payment_method] [nvarchar](50) NULL,
	[po_date] [datetime] NULL,
	[po_number] [nvarchar](50) NULL,
	[po_type] [nvarchar](50) NULL,
	[routing] [nvarchar](50) NULL,
	[salesperson] [nvarchar](50) NOT NULL,
	[sender_ID] [nvarchar](50) NULL,
	[ship_to_addr] [nvarchar](50) NULL,
	[ship_to_city] [nvarchar](50) NULL,
	[ship_to_contact_name] [nvarchar](50) NULL,
	[ship_to_contact_tel] [nvarchar](50) NULL,
	[ship_to_country] [nvarchar](50) NULL,
	[ship_to_id] [nvarchar](50) NULL,
	[ship_to_name] [nvarchar](50) NULL,
	[ship_to_state] [nvarchar](50) NULL,
	[ship_to_zip] [nvarchar](50) NULL,
	[special_code] [nvarchar](50) NULL,
	[status] [int] NOT NULL,
	[subday_desc] [nvarchar](50) NULL,
	[vendor_code] [nvarchar](50) NULL,
	[warehouse] [nvarchar](50) NULL,
 CONSTRAINT [PK_po_header] PRIMARY KEY CLUSTERED 
(
	[id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
GO


SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[po_item](
	[id] [int] IDENTITY(1,1) NOT NULL,
	[hid] [int] NOT NULL,
	[status] [int] NOT NULL,
	[routing] [nvarchar](50) NULL,
	[expected_ship_date] [datetime] NULL,
	[estimated_delivery_date] [datetime] NULL,
	[item_desc] [nvarchar](50) NULL,
	[ordered_qty] [decimal](18, 0) NULL,
	[UPC_code] [nvarchar](50) NULL,
	[vendor_item_number] [nvarchar](50) NULL,
	[ordered_unit] [nvarchar](50) NULL,
	[sku_num] [nvarchar](50) NULL,
	[po_line_num] [nvarchar](50) NULL,
	[unit_price] [decimal](18, 0) NULL,
 CONSTRAINT [PK_po_item] PRIMARY KEY CLUSTERED 
(
	[id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
GO

ALTER TABLE [dbo].[po_item]  WITH CHECK ADD  CONSTRAINT [FK_po_item_po_header] FOREIGN KEY([hid])
REFERENCES [dbo].[po_header] ([id])
GO

ALTER TABLE [dbo].[po_item] CHECK CONSTRAINT [FK_po_item_po_header]
GO


SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[POA_header](
	[id] [int] IDENTITY(1,1) NOT NULL,
	[create_date] [datetime] NOT NULL,
	[status] [int] NOT NULL,
	[po_ack_code] [nvarchar](50) NULL,
	[po_ack_date] [datetime] NULL,
	[po_ack_number] [nvarchar](50) NULL,
	[po_date] [datetime] NULL,
	[po_number] [nvarchar](50) NULL,
 CONSTRAINT [PK_POA_header] PRIMARY KEY CLUSTERED 
(
	[id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
GO


SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[POA_line](
	[id] [int] IDENTITY(1,1) NOT NULL,
	[status] [int] NOT NULL,
	[hid] [int] NOT NULL,
	[ack_qty] [decimal](18, 0) NULL,
	[estimated_delivery_date] [datetime] NULL,
	[line_item_status] [nvarchar](50) NULL,
	[order_line_number] [nvarchar](50) NULL,
	[ordered_qty] [decimal](18, 0) NULL,
	[po_line_num] [nvarchar](50) NULL,
	[request_reference_number] [nvarchar](max) NULL,
	[schedule_delivery_date] [datetime] NULL,
 CONSTRAINT [PK_POA_line] PRIMARY KEY CLUSTERED 
(
	[id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO

ALTER TABLE [dbo].[POA_line]  WITH CHECK ADD  CONSTRAINT [FK_POA_line_POA_header] FOREIGN KEY([hid])
REFERENCES [dbo].[POA_header] ([id])
GO

ALTER TABLE [dbo].[POA_line] CHECK CONSTRAINT [FK_POA_line_POA_header]
GO


SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[SH_header](
	[id] [int] IDENTITY(1,1) NOT NULL,
	[status] [int] NOT NULL,
	[asn_date] [datetime] NULL,
	[asn_number] [nvarchar](50) NULL,
	[carrier_name] [nvarchar](50) NOT NULL,
	[shipped_date] [datetime] NULL,
 CONSTRAINT [PK_SH_header] PRIMARY KEY CLUSTERED 
(
	[id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
GO


SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[SH_order](
	[id] [int] IDENTITY(1,1) NOT NULL,
	[hid] [int] NOT NULL,
	[po_number] [nvarchar](50) NOT NULL,
	[status] [int] NOT NULL,
 CONSTRAINT [PK_SH_order] PRIMARY KEY CLUSTERED 
(
	[id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
GO

ALTER TABLE [dbo].[SH_order]  WITH CHECK ADD  CONSTRAINT [FK_SH_order_SH_header] FOREIGN KEY([id])
REFERENCES [dbo].[SH_header] ([id])
GO

ALTER TABLE [dbo].[SH_order] CHECK CONSTRAINT [FK_SH_order_SH_header]
GO


SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[SH_pack](
	[id] [int] IDENTITY(1,1) NOT NULL,
	[oid] [int] NOT NULL,
	[length] [decimal](18, 0) NULL,
	[height] [decimal](18, 0) NULL,
	[width] [decimal](18, 0) NULL,
	[sscc_number] [nvarchar](50) NULL,
	[tracking_number] [nvarchar](50) NULL,
 CONSTRAINT [PK_SH_pack] PRIMARY KEY CLUSTERED 
(
	[id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
GO

ALTER TABLE [dbo].[SH_pack]  WITH CHECK ADD  CONSTRAINT [FK_SH_pack_SH_order] FOREIGN KEY([oid])
REFERENCES [dbo].[SH_order] ([id])
GO

ALTER TABLE [dbo].[SH_pack] CHECK CONSTRAINT [FK_SH_pack_SH_order]
GO




SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[SH_item](
	[id] [int] IDENTITY(1,1) NOT NULL,
	[oid] [int] NOT NULL,
	[pid] [int] NOT NULL,
	[status] [int] NOT NULL,
	[line_number] [nvarchar](50) NULL,
	[line_qty] [decimal](18, 0) NULL,
	[line_shipped_qty] [decimal](18, 0) NULL,
	[line_shipped_qty_unit] [nvarchar](50) NULL,
	[line_status] [nvarchar](50) NULL,
	[sku_number] [nvarchar](50) NULL,
	[tracking_number] [nvarchar](50) NULL,
	[vendor_item_number] [nvarchar](50) NULL,
	[reason_of_change] [nvarchar](255) NULL,
 CONSTRAINT [PK_SH_item] PRIMARY KEY CLUSTERED 
(
	[id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
GO

ALTER TABLE [dbo].[SH_item]  WITH CHECK ADD  CONSTRAINT [FK_SH_item_SH_pack] FOREIGN KEY([pid])
REFERENCES [dbo].[SH_pack] ([id])
GO

ALTER TABLE [dbo].[SH_item] CHECK CONSTRAINT [FK_SH_item_SH_pack]
GO

